package com.faithbj.controller.statistics;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.faithbj.common.model.Region;
import com.faithbj.service.RegionService;
import com.faithbj.utils.JsonUtils;

@Controller
@RequestMapping("/stat")
public class StatController extends StatBaseController{

	@Resource
	RegionService regionService;
	
	@RequestMapping("/getRegionList")
	@ResponseBody
	public String getRegionList(HttpServletRequest request, ModelMap model) {
		String regionId = request.getParameter("regionId");
		List<Region> regionList = regionService.getChildByRegionId(regionId);
		
		List<Map> regionListMap = new ArrayList<Map>();
		for(Region region : regionList) {
			Map regionMap = new HashMap();
			regionMap.put("id", region.getId());
			regionMap.put("name", region.getName());
			regionListMap.add(regionMap);
		}
		
		Map<String, List<Map>> data = new HashMap<String, List<Map>>();
		data.put("regionList", regionListMap);
		String jsonData  = JsonUtils.getJsonStrFromMap(data);
		System.out.println("getRegionList中的jsonData：" + jsonData);
		return jsonData;
	}
}
